#include "Log.hpp"
#include "UDP_Server.hpp"
#include <memory>
#include "Route.hpp"

// 服务端main逻辑，开启服务：接受并显示客户端发送的信息，最终把信息发回客户端
//  ./udpserver localip localport
int main(int args, char *argv[])
{
    // 对传入参数个数进行讨论
    if (args != 2)
    {
        std::cerr << "Usage: " << argv[0] << " port" << std::endl;
        exit(0);
    }

    uint16_t port = std::stoi(argv[1]);

    ENABLE_SCREEN();

    
    //把服务和网络关联起来
    Route route_service;

    Route::service_t route_func = std::bind(&Route::Foward,&route_service,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3);
    std::unique_ptr<UdpServer> upt = std::make_unique<UdpServer>(route_func/*回调函数*/,port);
    upt->Init();
    upt->Start();

    return 0;
}